<?php
header('Content-type:text/html;charset=utf8');
$config = [
    'host' => '127.0.0.1',
    'user' => 'root',
    'password' => 'root',
    'database' => 'php8_rainy',
    'charset' => 'utf8'
];
$dsn = sprintf("mysql:host=%s;dbname=%s;charset=%s"
    , $config['host'], $config['database'], $config['charset']);

try {
    $pdo = new PDO($dsn, $config['user'], $config['password']);
    // 设置获取的键的为大写
    // $pdo->setAttribute(PDO::ATTR_CASE, PDO::CASE_UPPER);
    // $pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_OBJ);
    $query = $pdo->query("SELECT * FROM news");
    $rows = $query->fetchAll(PDO::FETCH_OBJ);
    echo $rows[0]->title;
    // print_r($rows);
} catch (PDOException $e) {
    echo $e->getMessage();
}